package com.thf.message.listener;


import com.thf.model.Email;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

@Component
public class MessageListener {
    @Resource
    JavaMailSender javaMailSender;
    @Value("${spring.mail.username}")
    String from;
    @RabbitListener(queues = "thfQueue")
    public void receive(Email email) {
//        System.out.println("email---------------"+email);
        email.setFrom(from);
        SimpleMailMessage smm = new SimpleMailMessage();
        smm.setFrom(email.getFrom());
        smm.setTo(email.getTo());
        smm.setSubject(email.getSubject());
        smm.setText(email.getContent());
        javaMailSender.send(smm);
    }
}
